<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>护理不良事件上报详细表</title>
  <link rel="stylesheet" href="../layui/css/layui.css">
  <script src="../layui/layui.js"></script>
  <style>
    @page {
      width: 1200px ;
    }
    /*打印所用的css*/
    @media print {
      #button_bar {
        display: none;
      }

      #content_wrap {
        width: 1000px !important;
        /*布局的时候，为了给侧边栏留位置，给主体内容加了margin-left，现在需要去掉。*/
        margin-left: 0 !important;
        /*margin-bottom: 0 !important;*/
        /*margin-top: 0 !important;*/
        /*margin-right: 0 !important;*/
      }
    }
  </style>

</head>
<body>

<div class="layui-form-item" id="button_bar" >
  <div class="layui-input-block" style=" margin-top: 20px">
    <button type="button" class="layui-btn"  id = “back” onclick="self.location = document.referrer;">返回</button>
    <button type="button" class="layui-btn"  id="dayin">打印</button>
  </div>
</div>
<form class="layui-form" lay-filter="FormLoad" id="content_wrap">
  <!--startprint1-->
  <table border="1px" width="100%" cellpadding="0">
    <tr >
      <td colspan="6" style="text-align: center; height: 50px"> <span style=" font-size: 20px">护理不良事件报告表</span> </td>
    </tr>
    <tr>
      <div class="layui-form-item">
        <td colspan="1" width="16.6%">
          科室：
        </td>
        <td colspan="2" width="33.2%">
          <input type="text" name="reporter_department" placeholder="" class="layui-input" disabled>
        </td>
        <td colspan="1" width="16.2%">
          门诊号/住院号：
        </td>
        <td colspan="2" width="33.2%">
          <input type="text" name="patient_num" placeholder="" class="layui-input" disabled>
        </td>
      </div>
    </tr>
    <tr>
      <div class="layui-form-item">
        <td colspan="1">
          当事人：
        </td>
        <td colspan="2">
          <input type="text" name="witness" placeholder="" class="layui-input" disabled>
        </td>
        <td colspan="1">
          工作年限
        </td>
        <td colspan="2">
          <input type="text" name="reporter_work_year" placeholder="" class="layui-input" disabled>
        </td>
      </div>
    </tr>
    <tr>
      <div class="layui-form-item">
        <td>
          职称：
        </td>
        <td colspan="2">
          <input type="text" name="reporter_profession" placeholder="" class="layui-input" disabled>
        </td>
        <td colspan="1">
          报告人与其当事人的关系
        </td>
        <td colspan="2">
          <input type="text" name="reporter_relation_patient" placeholder="" class="layui-input" disabled>
        </td>
      </div>
    </tr>
    <tr>
      <div class="layui-form-item">
        <td>
          患者名字：
        </td>
        <td colspan="2">
          <input type="text" name="patient_name" placeholder="" class="layui-input" disabled>
        </td>
        <td colspan="1">
          诊断
        </td>
        <td colspan="2">
          <input type="text" name="bad_event_diagnose" placeholder="" class="layui-input" disabled>
        </td>
      </div>
    </tr>

    <tr>
      <div class="layui-form-item">
        <td>
          发生时间：
        </td>
        <td colspan="2">
          <input type="text" name="event_happen_time" id="event_happen_time" placeholder="" class="layui-input" disabled>
        </td>
        <td colspan="1">
          上报时间
        </td>
        <td colspan="2">
          <input type="text" name="event_report_time" id="event_report_time" placeholder="" class="layui-input" disabled>
        </td>
      </div>
    </tr>
    <tr>
      <div class="layui-form-item">
        <td>
          分级：
        </td>
        <td colspan="2">
          <input type="text" name="bad_event_level" placeholder="" class="layui-input" disabled>
        </td>
        <td colspan="1">
          报告人：
        </td>
        <td colspan="2">
          <input type="text" name="reporter" placeholder="" class="layui-input" disabled>
        </td>
      </div>
    </tr>
    <tr>
      <div class="layui-form-item">
        <td colspan="2">
          发生经过(发生时间，地点，事件内容，产生后果，采取的补偿措施与结果)：
        </td>
        <td colspan="4">
          <textarea name="bad_event_describe" style="height: 80px" required lay-verify="required" placeholder="" class="layui-textarea" disabled></textarea>
        </td>
      </div>
    </tr>
    <tr>
      <div class="layui-form-item">
        <td colspan="2">
          科内讨论分析（原因，教训，性质，处理意见）
        </td>
        <td colspan="4">
          <textarea name="department_analyse" style="height: 80px"  placeholder="" class="layui-textarea" disabled></textarea>
        </td>
      </div>
    </tr>
    <tr>
      <div class="layui-form-item">
        <td colspan="2">
          护理部质量安全会议及处理意见
        </td>
        <td colspan="4">
          <textarea name="nurse_department_analyse" style="height: 50px"  placeholder="" class="layui-textarea" disabled></textarea>
        </td>
      </div>
    </tr>
  </table>
  <!--endprint1-->

</form>
</body>

<script>

  let str;
  layui.use(['laydate','jquery','form','layedit','layer','table','laytpl'], function() {
    let $ = layui.jquery;
    let form = layui.form;
    let laydate = layui.laydate;
    var layer = layui.layer;
    var router = layui.router();
    laydate.render({
      elem: '#reporter_know_time' //指定元素
      , type: 'date'
    });
    laydate.render({
      elem: '#event_happen_time' //指定元素
      , type: 'date'
    });

    function getQueryVariable(variable)
    {
      let query = window.location.search.substring(1);
      let vars = query.split("&");
      for (let i=0;i<vars.length;i++) {
        let pair = vars[i].split("=");
        if(pair[0] == variable){return pair[1];}
      }
      return(false);
    }

    // 打印固定地方
    function preview(oper) {
      if (oper < 10){
        var bdhtml=window.document.body.innerHTML;//获取当前页的html代码
        var sprnstr="<!--startprint"+oper+"-->";//设置打印开始区域
        var eprnstr="<!--endprint"+oper+"-->";//设置打印结束区域
        var prnhtml=bdhtml.substring(bdhtml.indexOf(sprnstr)+18); //从开始代码向后取html

        prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr));//从结束代码向前取html
        window.document.body.innerHTML=prnhtml;
        window.print();
        window.document.body.innerHTML=bdhtml;

      }
      else{
        window.print();
      }

    }
//获取打印按钮
    $("#dayin").click(function() {
      onclick=preview(1);
    })


    form.render();
    // 获取地址的中的值
    let form_code=getQueryVariable("form_code");
    console.log(form_code);
    $.ajax({
      url: '/look?form_code=' + form_code,
      type: 'get',
      success: function (data) {
        console.log(data);
        let jsonObj = eval('(' + data + ')'); //获得jsonObj对象
        console.log(jsonObj);
        //渲染 上报人和上报人单位
        //let json = {};
        for(let i = 0; i<jsonObj.data.length; i++) {
          //给input 框 赋值
          $('input[name= '+ jsonObj.data[i].property_en_name +']').attr("value",jsonObj.data[i].detailed_data);
          // 给 textarea赋值
          $('textarea[name= '+ jsonObj.data[i].property_en_name +']').text(jsonObj.data[i].detailed_data);
        }
        //form.val("FormLoad",json)
      }
    });

  })
</script>

</html>